package com.charlotte.cliente;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.LabelElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;

/**
 *
 * @author law
 */
public class UiDatos implements ClickHandler
{
    
    private final Button btnIp = Button.wrap(Document.get().getElementById("ipB"));
    {
        btnIp.addClickHandler(this);
    }
    private final Button btnUa = Button.wrap(Document.get().getElementById("uaB"));
    {
        btnUa.addClickHandler(this);
    }
    private final LabelElement lblIp = (LabelElement)Document.get().getElementById("ipL");
    private final LabelElement lblUa = (LabelElement)Document.get().getElementById("uaL");
    private final CtrDatos ctr = new CtrDatos(this);
    public UiDatos(){}
    
    public void mostrarResultado(SubPath subPath,String result)
    {
        if(subPath.equals(SubPath.IP))
            this.lblIp.replaceChild(Document.get().createTextNode("IP = "+result),lblIp.getFirstChild());
        else 
            lblUa.replaceChild(Document.get().createTextNode("User Agent = "+result), lblUa.getFirstChild());
    }

    @Override
    public void onClick(ClickEvent event) 
    {
        if(event.getSource() == btnIp)
            clickEnBtnIp();
        else if(event.getSource() == btnUa)
            clickEnBtnUa();
    }
    
    public void clickEnBtnIp()
    {
        ctr.invocar(SubPath.IP);
    }
    
    public void clickEnBtnUa()
    {
        ctr.invocar(SubPath.USER_AGENT);
    }
    
    public void mostrarError(String error)
    {
        Window.alert(error);
    }
    
}
